package org.adorsys.aderp.jpa.impl;

import java.lang.reflect.Field;

import javax.persistence.Column;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ReflectionUtils.FieldFilter;

/**
 * Checks if the @Column(name="businessKey") or any combination of 
 * string containing the word businessKey
 * 
 * @author francis
 *
 */
public abstract class ColumnAnnotationFilter implements FieldFilter {
	
	private final String trailler;
	
	public ColumnAnnotationFilter(String trailler) {
		this.trailler = trailler;
	}

	@Override
	public boolean matches(Field field) {
		Column columnAnn = field.getAnnotation(Column.class);
		if(columnAnn==null) return false;
		return StringUtils.endsWith(columnAnn.name(), trailler);
	}
}
